#include <myheader.h>

/*Usage:  */
int main(int argc, char *argv[])
{
    char *ip = "192.168.112.129";
    char *port = "8080";

    //make a socket obj
    int socket_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    ERROR_CHECK(socket_fd,-1,"socket");

    //make a sockaddr struction
    struct sockaddr_in sockaddr;
    sockaddr.sin_family = AF_INET;
    sockaddr.sin_port = htons(atoi(port));
    sockaddr.sin_addr.s_addr = inet_addr(ip);

    //connect
    int ret = connect(socket_fd,(struct sockaddr*)&sockaddr,sizeof(sockaddr));
    ERROR_CHECK(ret,-1,"connect");

    //send
    char buf[60] = {0};
    int read_cnt = read(STDIN_FILENO,buf,sizeof(buf));
    ERROR_CHECK(read_cnt,-1,"read stdin");

    int send_cnt = send(socket_fd,buf,sizeof(buf),0);
    ERROR_CHECK(send_cnt,-1,"send");

    //close
    close(socket_fd);


    return 0;
}

